September 95 - Music the Easy Way: The QuickTime Music Architecture
Music the Easy Way: The QuickTime Music
Architecture
by David Van Brink
Music has become cheap and plentiful on the Macintosh, and many applications are now
making "casual" use of music. With the QuickTime Music Architecture, or QTMA,
including music in your application has never been simpler. Its API is straightforward
and easy to use, and you don't need intimate knowledge of MIDI protocols or channel and
voice numberings. Nor do you need an external MIDI device; QTMA can play music
directly out of the Macintosh's built-in speakers. And QTMA is widely available -- it's
on every Macintosh that has QuickTime 2.0 (or later) installed.
The QuickTime Music Architecture is perfect for adding a little bit of music to your
application. It has a set of well-supported high-level calls for playing musical notes
and sequences, it deals with MIDI protocols so that your application doesn't have to, and
it handles timing for entire tunes. With QTMA, you can specify musical instruments
independent of device, and play music either directly out of built-in speakers or
through a MIDI synthesizer.
QTMA first became available with QuickTime 2.0 and offers some new features in
QuickTime 2.1, which should be available through APDA by the time you read this. The
code in this article is written for version 2.1; minor changes will be required for 2.0.
(Before making use of the QuickTime 2.1 features, your code should call Gestalt with
the gestaltQuickTimeVersion selector and check the version number returned.)
This article shows how your application can use QTMA to play individual notes,
sequences of notes composed on the fly, or prescored sequences, and how to read input
from external MIDI devices. This issue's CD contains all the sample code and a THINK C
project to build and run it. We'll start with a look at QTMA in relation to other ways of
supporting music on the Macintosh; then we'll get down to business and play some
music with QTMA.
QTMA IN CONTEXT -- A LOOK AT MUSIC AND MIDI SUPPORT
ON THE MACINTOSH
Support for MIDI and musical applications on the Macintosh platform has a somewhat
checkered history. Developers have been faced with such options as writing their own
serial drivers, using the MIDI Manager, or using third-party operating system
extensions such as the Open Music System (OMS, formerly Opcode MIDI System) and
the Free MIDI System (FMS) from Mark of the Unicorn. None of these are practical for
adding just a little music to your application.
Writing a serial driver to send MIDI output to an Apple MIDI adapter or to any
third-party MIDI adapter isn't that complicated if you enjoy writing low-level code to
access hardware registers on the SCC serial chip. I say this in all seriousness: that
kind of code really is fun to write! But it's not the best way to do things, because
changes in the OS and hardware can render your work useless. And writing the
low-level serial code for MIDI input has additional complexities, primarily because of
the interrupt timings in many parts of the Mac OS.
The MIDI Manager is a slightly better tool to use for MIDI input and output.
Unfortunately, Apple's support for this product has been less than consistent, and the
MIDI Manager itself has some inherent performance limitations, though these are less
critical on faster hardware (68030 processor or better).
Both OMS and FMS are quite appropriate for professional music scoring and editing
products. Among the facilities that these extensions provide is a "studio configuration";
this lets the user describe to the system the various MIDI devices attached to the
computer so that different applications can access them.
All of these options have drawbacks for making casual use of music: you have to access
an external MIDI device, which most users don't have, and you have to use MIDI
protocols to talk to that device. QTMA frees you from both of these constraints. It also